//
//  TKYSelectedMemberController.m
//  StationHouseHelper
//
//  Created by apple on 2018/7/3.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYSelectedMemberController.h"
#import "TKYMineCell.h"
#import "TKYMineDetaileController.h"
@interface TKYSelectedMemberController ()<UITableViewDelegate,UITableViewDataSource>


@property (strong, nonatomic) NSMutableArray  *selectIndexs; //多选选中的行


///**显示数据的数组*/
//@property (nonatomic, strong)NSMutableArray *dataSourceArr;



@end

@implementation TKYSelectedMemberController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.tableView];
    self.selectDataArr = [NSMutableArray array];
    
    self.dataSourceArr = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"15", nil];
    // Do any additional setup after loading the view.
}
#pragma mark-- UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.results.count  >= 1 ) {
        return self.results.count;
    }else{
        return self.dataSourceArr.count;

    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TKYMineCell *cell = [tableView dequeueReusableCellWithIdentifier:kMineCellID];
    [cell.selectedBtn setImage:[UIImage imageNamed:@"非选中.png"] forState:UIControlStateNormal];
    //cell.selectedBtn.hidden = YES;
    if (self.results.count >=  1) {
        cell.nameLabel.text = self.results[indexPath.row];
    }else{
        cell.nameLabel.text = self.dataSourceArr[indexPath.row];
    }
    for (NSIndexPath *index in _selectIndexs) {
        if (indexPath == index) {
            [cell.selectedBtn setImage:[UIImage imageNamed:@"选中.png"] forState:UIControlStateNormal];
        }
    }
    
    cell.selecteCellBtnBlock = ^(UIButton *sender) {
        TKYMineCell *cell1 = [tableView cellForRowAtIndexPath:indexPath];
        
        if (cell1.selectedBtn.selected == YES ) { //如果为选中状态
            [cell1.selectedBtn setImage:[UIImage imageNamed:@"非选中.png"] forState:UIControlStateNormal];
            [self.selectDataArr removeObject:cell.nameLabel.text];

            cell1.selectedBtn.selected = NO;
            [_selectIndexs removeObject:indexPath]; //数据移除
        }else if(cell1.selectedBtn.selected == NO){ //未选中
            [cell1.selectedBtn setImage:[UIImage imageNamed:@"选中.png"] forState:UIControlStateNormal];
            cell1.selectedBtn.selected = YES;
            [self.selectDataArr addObject:cell.nameLabel.text];
           
            [_selectIndexs addObject:indexPath]; //添加索引数据到数组
        }
        NSLog(@"%@", self.selectIndexs);
        NSLog(@"%@", self.selectDataArr);
        //返回选中的数据
       //[[NSUserDefaults standardUserDefaults]setObject:self.selectDataArr forKey:@"data"];
        //[self.tableV reloadData];
    };
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    TKYMineDetaileController *mineDetaileVC = [[TKYMineDetaileController alloc]init];
    
    [self.navigationController pushViewController:mineDetaileVC animated:YES];
}

- (BaseTabelView *)tableView{
    if (_tableView == nil) {
        _tableView = [[BaseTabelView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerNib:[UINib nibWithNibName:@"TKYMineCell" bundle:nil] forCellReuseIdentifier:kMineCellID];
    }
    return _tableView;
}



@end
